﻿<Window x:Class="WpfClient.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="clr-namespace:Domain;assembly=Domain"
    Title="Window1" >
    <Window.Resources>
        <CollectionViewSource Source="{Binding AllDepartments}" x:Key="departments" />
        
        <DataTemplate DataType="{x:Type d:Department}">
            <Label Content="{Binding Name}" />
        </DataTemplate>
        
    </Window.Resources>
    
    <DockPanel LastChildFill="False" >
        <Border Margin="10" DockPanel.Dock="Top" HorizontalAlignment="Stretch" BorderBrush="Black" BorderThickness="1">
            <StackPanel HorizontalAlignment="Stretch" Orientation="Horizontal">
                <TextBox Name="IDtb" Width="100" Margin="5"/>
                <CheckBox Name="ckGetEnrollments" Margin="5">Fetch enrollments</CheckBox>
                <CheckBox Name="ckCourses" Margin="5">Fetch courses</CheckBox>
                <Button Click="Search" Margin="5">Search ID</Button>
            </StackPanel>
        </Border>
        
        <GroupBox DockPanel.Dock="Top" Margin="10" Header="Editing person" BorderBrush="Black" BorderThickness="2">
        <UniformGrid DataContext="{Binding Path=SelectedPerson}" Margin="10" Columns="2">
            <Label>LastName</Label>
            <TextBox Text="{Binding Path=LastName}" />

            <Label>FirstName</Label>
            <TextBox Text="{Binding Path=FirstName}" />

            <Label>HireDate</Label>
            <TextBox Text="{Binding Path=HireDate}" />

            <Label>EnrollmentDate</Label>
            <TextBox Text="{Binding Path=EnrollmentDate}" />
            
            <Label>Enrollments</Label>
            <ComboBox Name="cmbEnrollments" ItemsSource="{Binding Path=Enrollments}" >
                <ComboBox.ItemTemplate>
                    <DataTemplate>
                        <StackPanel Orientation="Horizontal">
                            <Label Content="{Binding Path=EnrollmentID}" />
                            <Label Content="{Binding Path=Grade}" />
                        </StackPanel>
                    </DataTemplate>
                </ComboBox.ItemTemplate>
            </ComboBox>

            <Label>Courses</Label>
            <ComboBox Name="cmbCourses" ItemsSource="{Binding Path=Courses}" >
                <ComboBox.ItemTemplate>
                    <DataTemplate>
                        <StackPanel Orientation="Horizontal">
                            <Label Content="{Binding Path=CourseID}" />
                            <Label Content="{Binding Path=Title}" />
                        </StackPanel>
                    </DataTemplate>
                </ComboBox.ItemTemplate>                
            </ComboBox>
        </UniformGrid>
        </GroupBox>
        
        <ContentPresenter DataContext="{Binding Path=SelectedPerson}" 
                          Margin="10" DockPanel.Dock="Top" Content="{Binding ElementName=cmbEnrollments, Path=SelectedItem}">
            <ContentPresenter.Resources>
                <DataTemplate DataType="{x:Type d:Enrollment}">
                    <GroupBox Header="Editing an Enrollment" BorderBrush="Black" BorderThickness="2">
                        <UniformGrid Columns="2">
                            <Label>ID</Label>
                            <Label Content="{Binding Path=EnrollmentID}" />
                            <Label>Grade</Label>
                            <TextBox Text="{Binding Path=Grade}" />
                            <Label>Person</Label>
                            <Label Content="{Binding Path=Person.LastName}" />
                            <Label />
                            <Button Click="RemoveEnrollment">Remove this Enrollment</Button>
                        </UniformGrid>
                    </GroupBox>
                </DataTemplate>
            </ContentPresenter.Resources>
        </ContentPresenter>

        <ContentPresenter DataContext="{Binding Path=SelectedPerson}" 
                          Margin="10" DockPanel.Dock="Top" Content="{Binding ElementName=cmbCourses, Path=SelectedItem}">
            <ContentPresenter.Resources>
                <DataTemplate DataType="{x:Type d:Course}">
                    <GroupBox Header="Editing a Course" BorderBrush="Black" BorderThickness="2">
                        <StackPanel>
                            <UniformGrid Columns="2">
                                <Label>ID</Label>
                                <Label Content="{Binding Path=CourseID}" />
                                <Label>Title</Label>
                                <TextBox Text="{Binding Path=Title}" />
                                <Label>Days</Label>
                                <TextBox Text="{Binding Path=Days}" />
                                <Label>Time</Label>
                                <TextBox Text="{Binding Path=Time}" />
                                <Label>Location</Label>
                                <TextBox Text="{Binding Path=Location}" />
                                <Label>Credits</Label>
                                <TextBox Text="{Binding Path=Credits}" />
                                <Label>Department</Label>
                                <ComboBox ItemsSource="{Binding Source={StaticResource departments}}" Tag="{Binding}"
                                          SelectedItem="{Binding Path=Department}" SelectionChanged="ChangedDepartment"/>
                                <Label />
                                <Button Click="RemoveCourse">Remove this Course</Button>
                            </UniformGrid>
                        </StackPanel>
                    </GroupBox>
                </DataTemplate>
            </ContentPresenter.Resources>
        </ContentPresenter>

        <Border Margin="10" DockPanel.Dock="Bottom" HorizontalAlignment="Stretch" BorderBrush="Black" BorderThickness="1">
            <StackPanel HorizontalAlignment="Stretch" Orientation="Horizontal">
                <StackPanel.Resources>
                    <Style TargetType="Button">
                        <Setter Property="Margin" Value="5" />
                    </Style>
                </StackPanel.Resources>
                <Button Click="BeginEdit">Begin Edit on person</Button>
                <Button Click="CancelEdit">Cancel Edit on person</Button>
                <Button Click="EndEdit">End Edit on person</Button>
                <Button Click="SaveGraph">Save entire Graph</Button>
                <Button Click="AddCourse">Add a new Course for this person</Button>
            </StackPanel>
        </Border>

    </DockPanel>
</Window>
